package jxc.base.helper;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Calendar;

/**
 * 生成单据序列
 * @author WZZ
 *
 */
public class Sequence {
	private static Integer sequence=0;
	private static int day=Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
	
	public static int getNext(){
		synchronized(sequence){
			if(Calendar.getInstance().get(Calendar.DAY_OF_MONTH)!=day){
				//新的一天到来了
				day=Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
				sequence=0;
			}
			return sequence++;
		}
	}
	
	public static String getNextInString(int length){
		NumberFormat format =  new DecimalFormat("000");
		format.setMaximumIntegerDigits(length);
		format.setMinimumIntegerDigits(length);
		format.setMinimumFractionDigits(0);
		format.setMaximumFractionDigits(0);
		return format.format(getNext());
	}
}
